<template>
  <a-modal :open="open" :width="680" title="修改病历名称" centered @cancel="onCancel" @ok="onOk">
    <a-form :model="formState" class="form-style-flex" :label-col="{ style: { width: '120px' } }">
      <a-form-item label="病历名称" v-bind="validateInfos.templateName" class="w-5/6 mt-8 mb-10">
        <a-input v-model:value="formState.templateName" placeholder="请输入" />
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script setup>
import { watch } from 'vue'
import { message } from 'ant-design-vue'

const props = defineProps({
  open: Boolean,
  rowData: {
    type: Object,
    default: () => ({})
  }
})
const emit = defineEmits(['update:open', 'success'])

const formState = ref({
  templateName: ''
})
watch(
  () => props.open,
  (val) => {
    if (val) {
      formState.value = { ...props.rowData }
    } else {
      formState.value = { templateName: '' }
      resetFields()
    }
  }
)
const rulesState = ref({
  // id: [{ required: true, message: '请选择上级目录' }],
  templateName: [{ required: true, message: '请输入病历名称' }]
})
const { resetFields, validateInfos } = useForm(formState, rulesState)
const onCancel = () => {
  resetFields()
  emit('update:open', false)
}
const onOk = async () => {
  const { code, msg } = await post('/emr/patientEmrDocument/doUpdatePatientEmrDocumentName', {
    id: formState.value.id,
    documentFileName: formState.value.templateName
  })
  if (code !== 0) return message.error(msg)
  message.success('修改成功')
  emit('success')
  onCancel()
}
</script>
<style lang="less" scoped></style>
